package com.example.userserver.controller;

import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.params.PageCityInfoParams;
import com.example.userserver.params.CityInfoParams;
import com.example.userserver.service.CityInfoService;
import com.example.userserver.vo.Result;
import com.example.userserver.vo.CityInfoVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user-server")
@Api(tags = "城市信息接口")
public class CityInfoController {
    @Autowired
    private CityInfoService cityInfoService;

    @ApiOperation(value = "获取分页城市")
    @PostMapping(value = "/pageCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<CityInfoVO>> pageCityInfo(@RequestBody PageCityInfoParams pageCityInfoParams) {
        return new Result(cityInfoService.pageCityInfo(pageCityInfoParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取城市列表")
    @GetMapping(value = "/listCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<List<CityInfoVO>> listCityInfo() {
        return new Result(cityInfoService.listCityInfo(), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取城市")
    @GetMapping(value = "/getCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<CityInfoVO> getCityInfo(@RequestParam String id) {
        return new Result(cityInfoService.getCityInfo(id), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除城市")
    @DeleteMapping(value = "/deleteCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteCityInfo(@RequestParam String id) {
        cityInfoService.deleteCityInfo(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改城市")
    @PutMapping(value = "/updateCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateCityInfo(@RequestBody CityInfoParams cityInfoParams) {
        return new Result(cityInfoService.updateCityInfo(cityInfoParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增城市")
    @PostMapping(value = "/insertCity")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertCityInfo(@RequestBody CityInfoParams cityInfoParams) {
        return cityInfoService.insertCityInfo(cityInfoParams);
    }

}
